package com.feituan.manager.controller;


import com.feituan.core.persistence.service.ICouponService;
import com.feituan.core.pojo.entity.Advice;
import com.feituan.core.pojo.entity.Coupon;
import com.feituan.core.pojo.request.AdvicePageReq;
import com.feituan.core.pojo.request.CommonPageReq;
import com.feituan.core.pojo.request.CouponSaveReq;
import com.feituan.core.pojo.response.Response;
import com.feituan.core.pojo.response.page.PageData;
import com.feituan.core.service.IAdviceBizService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.websocket.server.PathParam;
import java.util.Calendar;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xiaohu
 * @since 2024-05-09
 */
@RestController
@RequestMapping("/coupon")
@Api(tags = "优惠券管理")
public class CouponController extends BaseController{
    @Autowired
    private ICouponService iCouponService;
    @PostMapping("/list_page")
    @ApiOperation("")
    public Response<PageData<Coupon>> listPage(@Valid CommonPageReq request) {
        setDefaultPageParameters(request);
        return Response.success(iCouponService.queryPage(request));
    }

    @PostMapping("/save")
    @ApiOperation("id为空新增，id不为空修改")
    public Response<Boolean> save(@Valid CouponSaveReq request) {
        Coupon coupon=new Coupon();
        BeanUtils.copyProperties(request,coupon);
        if(coupon.getId() == null){
            coupon.setCreateTime(Calendar.getInstance().getTime());
            return response(iCouponService.save(coupon)) ;
        }else{
            return response(iCouponService.updateById(coupon));
        }
    }
    @PostMapping("/delete")
    @ApiOperation("")
    public Response<Boolean> delete(Long id) {
        return response(iCouponService.removeById(id));
    }
}
